package com.dlc.shop.jky.common.service.impl;

import com.alibaba.fastjson.JSONObject;

import com.linchuang.seneca.jky.bizdata.core.BaseResponseBizData;
import com.linchuang.seneca.jky.bizdata.vend.vendget.core.VendGetRequestBizData;
import com.linchuang.seneca.jky.bizdata.vend.vendget.core.VendGetResponseBizData;
import com.linchuang.seneca.jky.exception.JkyException;
import com.linchuang.seneca.jky.response.JackyunResponse;
import com.dlc.shop.common.jky.JkyMp;
import com.dlc.shop.config.ShopConfig;

import com.dlc.shop.jky.common.service.JackyunOpenClientService;
import com.dlc.shop.jky.common.service.JkyService;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.format.DateTimeFormatter;

@Service
@Slf4j
@AllArgsConstructor
public class jkyServiceimpl implements JkyService {

   public final ShopConfig shopConfig;
   public final JackyunOpenClientService jackyunOpenClientService;

   @Override
   public VendGetResponseBizData getVendGetResponseBizData() throws JkyException {
      VendGetRequestBizData vendGetRequestBizData = new VendGetRequestBizData();
      vendGetRequestBizData.setPageIndex(0);
      vendGetRequestBizData.setPageSize(50);
      vendGetRequestBizData.setMethod("erp.vend.get");
      JkyMp jky = shopConfig.getJky();

      JackyunResponse call = jackyunOpenClientService.call(jky, vendGetRequestBizData);
      if ("0".equals(call.getCode())) {
         throw new JkyException("0", call.getMsg() + vendGetRequestBizData.toString());
      }
      //BaseResponseBizData.Result jackyunResponse = JSONObject.parseObject(call.getResult().toString()).toJavaObject( BaseResponseBizData.Result.class);
      JSONObject data = JSONObject.parseObject(call.getResult().toString());
      String data1 = data.get("data").toString();
      //转化为需要的数据
      VendGetResponseBizData orderRequest = JSONObject.parseObject(data1).toJavaObject(VendGetResponseBizData.class);
      System.out.println(orderRequest.getVendInfo());
      return orderRequest;
   }
}
